define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shopro/group/identity/index' + location.search,
                    add_url: 'shopro/group/identity/add',
                    edit_url: 'shopro/group/identity/edit',
                    table: 'shopro_group_identity',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'activity_id', title: '团ID'},
                        {field: 'activity_groupon_id', title: '活动ID'},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'nickname', title: '用户昵称'},
                        {field: 'member_type', title: '团长类型',operate:false,searchList: {"3":'',"1":'官审',"2":'非官审'}, formatter: Table.api.formatter.normal},
                        {field: 'level', title: '团长等级',operate:false,searchList: {"3":'小小团长',"1":'大团长',"2":'小团长'}, formatter: Table.api.formatter.normal},
                        {field: 'parent_user_id', title: '上级团长ID'},
                        {field: 'parent_user_id', title: '上级团长昵称'},
                        {field: 'order_id', title: '订单ID'},
                        {field: 'status', title: '审核状态',searchList: {"0":'待审核',"1":'已审核',"2":'冻结中'}, formatter: Table.api.formatter.normal},
                        {field: 'commission_type', title: '提成类型', operate:false,operate:false,searchList: {"3":'',"1":'固定金额',"0":'百分比'}, formatter: Table.api.formatter.normal},
                        {field: 'commission_money', title: '提成金额', operate:false},
                        {field: 'commission_bili', title:  '提成比例', operate:false},
                        {field: 'createtime', title: '申请时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'verificationtime', title: '通过时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
